package com.java110.mall.goods.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.allocationOrder.AllocationOrderProductDto;
import com.java110.mall.goods.bmo.allocationOrderProduct.IDeleteAllocationOrderProductBMO;
import com.java110.mall.goods.bmo.allocationOrderProduct.IGetAllocationOrderProductBMO;
import com.java110.mall.goods.bmo.allocationOrderProduct.ISaveAllocationOrderProductBMO;
import com.java110.mall.goods.bmo.allocationOrderProduct.IUpdateAllocationOrderProductBMO;
import com.java110.po.allocationOrderProduct.AllocationOrderProductPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/allocationOrderProduct")
public class AllocationOrderProductApi {

    @Autowired
    private ISaveAllocationOrderProductBMO saveAllocationOrderProductBMOImpl;
    @Autowired
    private IUpdateAllocationOrderProductBMO updateAllocationOrderProductBMOImpl;
    @Autowired
    private IDeleteAllocationOrderProductBMO deleteAllocationOrderProductBMOImpl;

    @Autowired
    private IGetAllocationOrderProductBMO getAllocationOrderProductBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /allocationOrderProduct/saveAllocationOrderProduct
     * @path /app/allocationOrderProduct/saveAllocationOrderProduct
     */
    @RequestMapping(value = "/saveAllocationOrderProduct", method = RequestMethod.POST)
    public ResponseEntity<String> saveAllocationOrderProduct(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含orderId");
        Assert.hasKeyAndValue(reqJson, "srcProductId", "请求报文中未包含srcProductId");
        Assert.hasKeyAndValue(reqJson, "targetProductId", "请求报文中未包含targetProductId");


        AllocationOrderProductPo allocationOrderProductPo = BeanConvertUtil.covertBean(reqJson, AllocationOrderProductPo.class);
        return saveAllocationOrderProductBMOImpl.save(allocationOrderProductPo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /allocationOrderProduct/updateAllocationOrderProduct
     * @path /app/allocationOrderProduct/updateAllocationOrderProduct
     */
    @RequestMapping(value = "/updateAllocationOrderProduct", method = RequestMethod.POST)
    public ResponseEntity<String> updateAllocationOrderProduct(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含orderId");
        Assert.hasKeyAndValue(reqJson, "srcProductId", "请求报文中未包含srcProductId");
        Assert.hasKeyAndValue(reqJson, "targetProductId", "请求报文中未包含targetProductId");
        Assert.hasKeyAndValue(reqJson, "detailId", "detailId不能为空");


        AllocationOrderProductPo allocationOrderProductPo = BeanConvertUtil.covertBean(reqJson, AllocationOrderProductPo.class);
        return updateAllocationOrderProductBMOImpl.update(allocationOrderProductPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /allocationOrderProduct/deleteAllocationOrderProduct
     * @path /app/allocationOrderProduct/deleteAllocationOrderProduct
     */
    @RequestMapping(value = "/deleteAllocationOrderProduct", method = RequestMethod.POST)
    public ResponseEntity<String> deleteAllocationOrderProduct(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "detailId", "detailId不能为空");


        AllocationOrderProductPo allocationOrderProductPo = BeanConvertUtil.covertBean(reqJson, AllocationOrderProductPo.class);
        return deleteAllocationOrderProductBMOImpl.delete(allocationOrderProductPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 商铺ID
     * @return
     * @serviceCode /allocationOrderProduct/queryAllocationOrderProduct
     * @path /app/allocationOrderProduct/queryAllocationOrderProduct
     */
    @RequestMapping(value = "/queryAllocationOrderProduct", method = RequestMethod.GET)
    public ResponseEntity<String> queryAllocationOrderProduct(@RequestParam(value = "shopId") String shopId,
                                                              @RequestParam(value = "page") int page,
                                                              @RequestParam(value = "row") int row) {
        AllocationOrderProductDto allocationOrderProductDto = new AllocationOrderProductDto();
        allocationOrderProductDto.setPage(page);
        allocationOrderProductDto.setRow(row);
        allocationOrderProductDto.setShopId(shopId);
        return getAllocationOrderProductBMOImpl.get(allocationOrderProductDto);
    }
}
